package com.prs.crm.action.person;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.StaffState;
import com.prs.crm.service.person.StaffStateService;

public class StaffStateAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private StaffState	staffState;
	private StaffStateService staffStateService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public StaffState getStaffState() {
		return staffState;
	}
	public void setStaffState(StaffState staffState) {
		this.staffState = staffState;
	}
	public StaffStateService getStaffStateService() {
		return staffStateService;
	}
	public void setStaffStateService(StaffStateService staffStateService) {
		this.staffStateService = staffStateService;
	}
	
	
	@Action("listStaffState")
	public String listStaffState(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(StaffState.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getStaffStateService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editStaffState")
	public String editStaffState(){
		if(ids!=null){
			this.staffState=this.getStaffStateService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="saveStaffState",results={
			@Result(name="success",type="redirect",location="listStaffState"),
			@Result(name="error",type="chain",location="editStaffState")
	})
	public String saveStaffState(){
		this.getStaffStateService().save(staffState);
		return SUCCESS;
	}
	@Action(value="removeStaffState",results={
			@Result(name="success",type="redirect",location="listStaffState"),
			@Result(name="error",type="chain",location="listStaffState")
	})
	public String removeStaffState(){
		if(ids==null){
			this.addActionError("请选一行进行操作！");
			return ERROR;
		}
		this.getStaffStateService().batchRemove(ids);
		return SUCCESS;
	}
}
